home *** CD-ROM | disk | FTP | other *** search
- -- 2000.02.26
- -- Clive Green <clivegreen@atlas.co.uk>
-
- ------------------------------------------------------------------------------------------------------
-
- -- this offers rudimentary cursor control, using static 1-bit bitmap custom cursors.
-
- ------------------------------------------------------------------------------------------------------
-
- -- declare properties:
- property main -- main code directory object
- property cursorList -- a runtime-compiled #proplist of known custom cursors
-
- ------------------------------------------------------------------------------------------------------
-
- on new me,L
-
- -- (1) extract and check arguments:
-
- -- check for a parameter list:
- if ilk(L) <> #propList then return [#error:#noParamListSupplied, #msg:"cursorService:new"]
-
- -- a reference to the parent codebase is REQUIRED:
- main = L[#main]
- if (ilk(main) <> #instance) then return ¬
- [#error:#noMainObjectSupplied, #msg:"cursorService:new"]
-
- --------------------
-
- -- (2) compile a list of known custom cursors:
- o = me.compileCursors()
- if (ilk(o) <> #instance) then return o
-
- -- pass back my address:
- return me
-
- ----------------------------------------------------------------------------------------------------
-
- on compileCursors me
-
- -- This simply compiles a list of custom 1-bit cursors by examining the contents of an
- -- attached castlib called "cursors". 1-bit cursors (currently) avoid the flicker problem
- -- encountered when using 'cursor asset' cursors over Flash 4 movie sprites within a D7 movie.
-
- -- Each cursor is stored as a linear list [] containing a cursor and (optionally) a mask
- -- castmember number, and each cursor is uniquely named.
-
- -- Note that the preparation and naming of cursor graphics is important here ; a cursor called
- -- #myArrow would become available to the programme only if there exists a 1-bit graphic castmember
- -- called "myArrow cursor" within the "cursors" castlibrary (an optional member called "myArrow
- -- mask" would be used as the cursor mask.)
-
- --------------------
-
- -- (1) first declare all literals:
-
- -- what cursor castmember name suffixes are used?
- suffixList = [:]
- suffixList[#cursor] = "cursor"
- suffixList[#mask] = "mask"
-
- -- and in what castlibrary?
- cursorLibName = "cursors"
- c = castlib(cursorLibName).number
-
- --------------------
-
- -- initialise the storage listing:
- cursorList = [:]
-
- -- gather 1-bit cursor information:
- repeat with i = 1 to the number of members of castlib c
-
- -- examine each member's type - we want 1-bit cursor bitmap graphics ONLY:
- n = member(i,c).number
- t = member(n).type
-
- if t <> #bitmap then next repeat
- if member(n).depth > 8 then next repeat
-
- -- pull the cursor's prefix and suffix strings:
- x = member(n).name
- a = symbol(word 1 of x)
- b = the last word of x
-
- -- is b a recognised suffix string?
- z = getPos(suffixList,b)
- if not z then next repeat
-
- -- what is the storage #label for an element with this suffix?
- z = getPropAt(suffixList,z)
-
- -- does a listed entry for cursor (a) already exist?
- L = cursorList[a]
- if not listP(L) then
-
- -- create a new storage listing for cursor a:
- L = [:]
- cursorList[a] = L
-
- end if
-
- -- now store the member number n using the suffix z:
- L[z] = n
-
- end repeat
-
- --------------------
-
- -- now convert the compiled cursor listing into a series of listed cursor/mask pairs:
- repeat with i = 1 to count(cursorList)
-
- -- get the ith list of cursor bitmaps:
- L1 = cursorList[i]
-
- -- create a linear storage list to hold extracted bitmap members:
- L2 = []
-
- -- look for the REQUIRED #cursor element:
- c = L1[#cursor]
- if not integerP(c) then
-
- -- set the data list for the ith cursor to an empty linear list:
- cursorList[i] = []
- next repeat
-
- end if
-
- -- store this element:
- add L2,c
-
- -- look for an optional #mask element:
- m = L1[#mask]
- if integerP(m) then add L2,m
-
- -- replace the ith list cursor data with a validated and ordered linear list:
- cursorList[i] = L2
-
- end repeat
-
- -- flag success to caller:
- return me
-
- ----------------------------------------------------------------------------------------------------
-
- on setCursor me,L
-
- -- extract a valid cursor ID:
- if ilk(L) <> #propList then return 0
-
- c = L[#cursorID]
- if not symbolP(c) then return 0
-
- -- try to obtain a recognised cursor:
- cL = cursorList[c]
- if not listP(cL) then return 0
- if not count(cL) then return 0
-
- --------------------
-
- -- cL will contain either one or two bitmap member numbers, with the foreground element always
- -- listed first:
-
- -- set a valid cursor:
- cursor cL
-
- -- flag success:
- return 1
-
- ----------------------------------------------------------------------------------------------------
-
- on clearCursor me
-
- -- unconditionally reset:
- cursor 0
-
- -- flag success:
- return 1
-
- ----------------------------------------------------------------------------------------------------